﻿using Quartz;
using Quartz.Impl;
using Quartz.Impl.Matchers;
using QuartzNetDemo.s1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuartzNetDemo.s2
{
    public class Schedule1
    {
        /// <summary>
        /// Quartz中的AOP思想
        /// </summary>
        public static void Show()
        {
            //1.创建Schedule
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

            //2.创建job (具体的job需要单独在一个文件中执行)
            var job = JobBuilder.Create<HelloJob>().Build();

            //3.配置trigger   1s执行一次
            var trigger = TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(1)
                                                                           .RepeatForever()).Build();
            //AOP配置
            scheduler.ListenerManager.AddJobListener(new MyAopListener(), GroupMatcher<JobKey>.AnyGroup());

            //4.将job和trigger加入到作业调度池中
            scheduler.ScheduleJob(job, trigger);

            //5. 开始调度
            scheduler.Start();
        }
    }
}
